'''
kook和discord机器人版本代码，目前还不会封装，就不献丑了
'''
# 离线 命令行版本查询数据
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import sys
import time
import readline
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities # get直接返回，不再等待界面加载完成
import os
import numpy as np

os.system('') # 解决win10无法显示转移字码颜色


# ANSI 转义码定义
RESET = "\033[0m"      # 重置所有属性
# 前景色
BLACK = "\033[30m"
RED = "\033[31m"
GREEN = "\033[32m"
YELLOW = "\033[33m"
BLUE = "\033[34m"
MAGENTA = "\033[35m"
CYAN = "\033[36m"
WHITE = "\033[37m"

side_eng_to_cn = {'':'', 'PLA':'中国(PLA)', 'PLANMC':'中国海军陆战队(PLANMC)', 'USA':'美国(USA)',
                  'USMC':'美国海军陆战队(USMC)', 'RUS':'俄罗斯(RUS)', 'VDV':'俄罗斯空降兵(VDV)',
                  'GB':'英国(GB)', 'CAF':'加拿大(CAF)', 'AUS':'澳大利亚(AUS)', 'INS':'老乡(INS)',
                  'MEA':'中东联盟(MEA)', 'IMF':'民兵(IMF)'}

# 因为html元素的id不是两个词，所以如果地图是两个词的话，所以要转换一下
map_dict = {'Al Barsrah':'AlBasrah', 'Fool\'s Road':'FoolsRoad', 'Goose Bay':'GooseBay', 'Kamdesh Highlands':'Kamdesh',
            'Kohat Toi':'Kohat', 'Lashkar Valley':'Lashkar', 'Logar Valley':'Logar', 'Sumari Bala':'Sumari',
            'Tallil Outskirts':'Tallil', 'Black Coast':'BlackCoast'
            }

map_complete = {'Anvil', 'Al Barsrah', 'Belaya', 'Chora', 'Fallujah',
               'Fool\'s Road', 'Goose Bay', 'Gorodok', 'Kamdesh Highlands',
               'Kohat Toi', 'Kokan', 'Lashkar Valley', 'Logar Valley', 'Manicouagan',
               'Mestia', 'Mutaha', 'Narva', 'Skorpo', 'Sumari Bala', 'Tallil Outskirts',
               'Yehorivka', 'Black Coast', 'Harju'}
mode_complete = {'RAAS', 'AAS', 'Invasion', 'Seed', 'TC'} # 还未支持Tank模式
team_complete = {'PLA', 'PLANMC', 'USA', 'USMC', 'RUS', 'VDV', 'GB', 'CAF',
                 'AUS', 'INS', 'MEA', 'IMF'}

def help():

    s = f'目前Tank模式还不支持\n查询查询格式为(不区分大小写): 当前地图前三个英文字母 模式首字母' \
        f'第几张地图 下张地图前三个英文字母 模式首字母 第几张地图 当前阵营\n' \
        f'比如说这场比赛Narva RAAS v4, 下场比赛Mutaha RAAS v3, 你现在是加军\n' \
        f'就输入: nar r 4 mut r 3 cdf\n'
    print(s)
    print('以下是阵容英文缩写对照表：')
    for i, key in enumerate(side_eng_to_cn):
        if i == 0:
            continue
        # print(it.key, it.value)
        print(i, side_eng_to_cn[key])


# 处理两个单词地图的情况(比如：Talil Outskirts)
def parse_input(c : list):
    map1, mode1, version1, map2, mode2, version2 = '', '', '', '', '', ''
    if len(c) == 7: # 正常情况，两张地图都是一个词
        map1, mode1, version1, map2, mode2, version2 = c[0], c[1], c[2], c[3], c[4], c[5]
    elif len(c) == 8: # 一张地图两个单词，一张地图一个单词
        if c[1] not in  ['RAAS', 'AAS', 'Invasion', 'Seed', 'Tanks', 'Seed', 'TC']: # 第一张地图两个单词
            map1, mode1, version1, map2, mode2, version2 = map_dict[c[0] + ' ' + c[1]], c[2], c[3], c[4], c[5], c[6]
        else: # 第二张地图两个单词
            map1, mode1, version1, map2, mode2, version2 = c[0], c[1], c[2], map_dict[c[3] + ' ' + c[4]], c[5], c[6]
    else: # 两张地图都是两个词
        assert len(c) == 9
        map1, mode1, version1, map2, mode2, version2 = map_dict[c[0] + ' ' + c[1]], c[2], c[3], map_dict[c[4] + ' ' + c[5]], c[6], c[7]

    return map1, mode1, version1, map2, mode2, version2, c[-1]

# 更新本场比赛地图
def update_now_map(map_arg, mode_arg, version_arg):
    version = int(version_arg)
    special_zero = ''  # 因为他妈的如果地图大于10，就会变成0几，所以要特判某些地图
    if mode_arg == 'RAAS' and version < 10:  # 只有RAAS会地图大于10，其他模式目前还没大于10的
        if map_arg == 'Gorodok' or map_arg == 'Kohat' or  map_arg == 'Yehorivka':
            special_zero = '0'

    file_path = './data/' + map_arg + '/' + mode_arg + ' v' + special_zero + str(version) + '/car_info.npy'
    dict = np.load(file_path, allow_pickle=True).item()
    team1, team2 = list(dict.keys())[0], list(dict.keys())[1]
    return team1, team2


# 查询你所在下场比赛地图阵营
def query_next_map(map_arg, mode_arg, version_arg, side_arg):
    version = int(version_arg)
    special_zero = ''  # 因为他妈的如果地图大于10，就会变成0几，所以要特判某些地图
    if mode_arg == 'RAAS' and version < 10:  # 只有RAAS会地图大于10，其他模式目前还没大于10的
        if map_arg == 'Gorodok' or map_arg == 'Kohat' or  map_arg == 'Yehorivka':
            special_zero = '0'

    file_path = './data/' + map_arg + '/' + mode_arg + ' v' + special_zero + str(version) + '/car_info.npy'

    dict = np.load(file_path, allow_pickle=True).item()
    team1, team2 = list(dict.keys())[0], list(dict.keys())[1]

    print('---------------')
    if side_arg == 1: # 第一队
        print(MAGENTA + '下一场你是', GREEN + team1 + RESET, MAGENTA + '阵营' + RESET)
        for value in dict[team1]:
            print(GREEN + value + RESET)
        print(MAGENTA + '敌方是', RED + team2 + RESET, MAGENTA + '阵营' + RESET)
        for value in dict[team2]:
            print(RED + value + RESET)

    else: # 第二队
        assert side_arg == 2 # 第二队
        print(MAGENTA + '下一场你是', GREEN + team2 + RESET, MAGENTA + '阵营' + RESET)
        for value in dict[team2]:
            print(GREEN + value + RESET)
        print(MAGENTA + '敌方是', RED + team1 + RESET, MAGENTA + '阵营' + RESET)
        for value in dict[team1]:
            print(RED + value + RESET)

# 对输入进行补全
def complete_input(map1_arg, model1_arg, version1_arg, map2_arg, model2_arg, version2_arg, team_arg):
    res = []
    # 下面7个代码块分别是对7个输入参数进行补全
    ava = [option for option in map_complete if option.lower().startswith(map1_arg.lower())]
    res.append(ava[0])

    ava = [option for option in mode_complete if option.lower().startswith(model1_arg.lower())]
    res.append(ava[0])

    res.append(version1_arg)

    ava = [option for option in map_complete if option.lower().startswith(map2_arg.lower())]
    res.append(ava[0])

    ava = [option for option in mode_complete if option.lower().startswith(model2_arg.lower())]
    res.append(ava[0])

    res.append(version2_arg)

    ava = [option for option in team_complete if option.lower().startswith(team_arg.lower())]
    res.append(ava[0])

    return res


def work(map1_arg, model1_arg, version1_arg, map2_arg, model2_arg, version2_arg, team_arg):

    # 补全输入信息
    completed_input = complete_input(map1_arg, model1_arg, version1_arg, map2_arg, model2_arg, version2_arg, team_arg)
    # 解析补全后的输入
    map1_arg, model1_arg, version1_arg, map2_arg, model2_arg, version2_arg, team_arg = parse_input(completed_input)

    team1, team2 = update_now_map(map1_arg, model1_arg, version1_arg)
    # print(team1, team2)
    #     print('你本场比赛是 ' + side_eng_to_cn[team1] + ' 还是 ' + side_eng_to_cn[team2] + ' 阵营?输入括号里的英文缩写')
    now_side = team_arg
    next_side = -1  # 下场比赛是哪边阵营
    if now_side == team1:
        next_side = 2
    elif now_side == team2:
        next_side = 1
        # print(RED + '阵营输错啦' + RESET)
        # assert(False)

    query_next_map(map2_arg, model2_arg, version2_arg, next_side)

while True:
    # help()
    a = input().split()
    try:
        work(a[0], a[1], a[2], a[3], a[4], a[5], a[6])
    except Exception as e:
        print('出错了 :', e)

